{include file="public/toper" /}
<script type="text/javascript" src="/static/js/myajax.js"></script>
<div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">日志管理</a>
        <a href="">日志列表</a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>

<div class="x-body">
    <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
            <input type="text" value="" id="key"  style="width:250px;"  placeholder="请输入标题、ip、内容" autocomplete="off" class="layui-input">
            <input type="text" id="riqi" value=""  placeholder="选择日期" style="width:250px;"  class="layui-input" readonly='readonly'>
            <button class="layui-btn" id="search"><i class="layui-icon">&#xe615;</i></button>
        </div>
    </div>
    <xblock class="demoTable">
        <button class="layui-btn layui-btn-danger" data-type="getCheckData"><i class="layui-icon"></i>批量删除</button>
    </xblock>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script>
    layui.use(['table','util','laydate'], function(){
        var table = layui.table, $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var loading = layer.load(1, {shade: [0.1,'#fff'] });
        var tableIn = table.render({
            method: 'post',
            elem: '#test'
            ,url: "{:url('Log/index')}"
            ,id:'test'
            ,cols: [[
                {type:'checkbox'}
                ,{field:'store_id', width:80, title: '序号',align: 'center',type:'numbers'}
                ,{field: 'a_id',width:150, title: '操作人', templet:function(d){return d.a_name.name;}}
                ,{field:'title', width:150,title: '操作',align: 'center'}
                ,{field:'url', width:250,title: '操作地址',align: 'center'}
                ,{field:'param', width:500, title: '操作参数',align: 'center'}
                ,{field:'ip', width:200, title: 'IP',align: 'center'}
                ,{field: 'create_time',width: 180, sort:'true',title: '操作时间', templet: '<div>{{layui.util.toDateString(d.create_time*1000) }}</div>'}
            ]]
            ,page: true
            ,limit: 30
            ,limits:[30,60,90,120,150,180,210,240,270,300]
        });
        layer.close(loading);

        laydate.render({
            elem: '#riqi'
            ,type: 'datetime'
            ,range: true
        });


        //搜索
        $('#search').on('click', function () {
            var loading = layer.load(1, {shade: [0.1,'#fff'] });
            tableIn.reload({
                where: {key: $('#key').val(),sj:$('#riqi').val()},
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            layer.close(loading);
        });


        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('test')
                    ,data = checkStatus.data;

                //layer.alert(JSON.stringify(data));
                var d = JSON.stringify(data)
                console.log(d);
                var str = new Array();
                if(data.length>0){
                    for(var i=0;i<data.length;i++){
                        str[i] = data[i].id;
                    }
                    var loading = layer.load(1, {shade: [0.1,'#fff'] });

                    $.post("{:url('Log/del')}",{id:str},function(res){
                        layer.close(loading);
                        if(res.code==200){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload({});
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });


                }else{
                    layer.msg("请选择要删除的数据",{time:1000,icon:2});
                }

            }
        };



        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });
</script>
{include file="public/footer"/}